package com.yuma.sync;

import java.util.concurrent.TimeUnit;

class Phone {
    public synchronized static void sendSMS() throws InterruptedException {   // Phone.class 锁对象
        TimeUnit.SECONDS.sleep(4);   // sleep锁不释放
        System.out.println("sendSMS");
    }
    public synchronized void sendEmail() { // phone 锁对象
        System.out.println("sendEmail");
    }
    public void hello() {
        System.out.println("hello");
    }
}
public class Sync8LockDemo {
    public static void main(String[] args) {
        //  线程操作资源类
        Phone phone = new Phone();
        Phone phone2 = new Phone();
        //  调用发短信
        new Thread(()->{
            try {
                phone.sendSMS();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }).start();
        //  调用发邮件
        new Thread(()->{
            //phone.sendEmail();
            //phone.hello();
            //phone2.sendEmail();
            phone2.hello();
        }).start();
    }
}
